package com.study.web.controller.message;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.study.app.domain.bo.AppSystemNotificationsBo;
import com.study.app.domain.vo.AppSystemNotificationsVo;
import com.study.app.service.IAppSystemNotificationsService;
import com.study.common.core.controller.AppBaseController;
import com.study.common.core.domain.PageQuery;
import com.study.common.core.domain.R;
import com.study.common.core.page.TableDataInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 系统消息 -- 系统消息
 */

@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system")
public class SystemMessageController extends AppBaseController {

    private final IAppSystemNotificationsService iAppSystemNotificationsService;

    /**
     * 用户获取系统消息列表
     *
     * @param pageQuery
     * @return
     */
    @SaCheckLogin
    @GetMapping("/message")
    public R<TableDataInfo<AppSystemNotificationsVo>> getUserMessageList(PageQuery pageQuery) {
        return R.ok(iAppSystemNotificationsService.queryPageListById(getUserId(), pageQuery));
    }

    /**
     * 系统消息详情
     *
     * @param notificationId
     * @return
     */
    @SaCheckLogin
    @GetMapping("/particulars")
    public R<AppSystemNotificationsVo> getMessageParticulars(@Valid Long notificationId) {
        iAppSystemNotificationsService.updateMessageRead(notificationId);
        return R.ok(iAppSystemNotificationsService.queryById(notificationId));
    }
    /**
     * 获取当前用户车辆请求弹框提示
     */
    @SaCheckLogin
    @GetMapping("/vehicleSharingPopMessage")
    public R<AppSystemNotificationsVo> getVehicleSharingPopMessage() {
        return R.ok(iAppSystemNotificationsService.queryVehicleSharingPopMessage());
    }
    /**
     * 获取当前用户车辆请求消息蒙版提示
     */
    @SaCheckLogin
    @GetMapping("/vehicleSharingTipMessage")
    public R<AppSystemNotificationsVo> getVehicleSharingTipMessage() {
        return R.ok(iAppSystemNotificationsService.queryVehicleSharingTipMessage());
    }
    /**
     * 消息已读
     */
    @SaCheckLogin
    @GetMapping("/readMessage")
    public R<Void> editMessageReadStatus(@Valid Long notificationId) {
        return toAjax(iAppSystemNotificationsService.updateMessageRead(notificationId));
    }

}
